package com.learn.demo.config;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.MeterBinder;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author banjiawei
 * @date 2021/03/16
 * 注册
 */
@Component
public class CharMetrics implements MeterBinder {
    public Counter counterOne;
    public Counter counterTwo;
    public Counter counterThree;

    public Map<String, Long> map;

    CharMetrics(){
        this.map = new HashMap<>();
    }
    @Override
    public void bindTo(MeterRegistry meterRegistry) {
        this.counterOne = Counter.builder("com.citydo.micrometerspingboot").tags(new String[]{"name","counterOne"}).description("This is the one counter").register(meterRegistry);
        this.counterTwo = Counter.builder("com.citydo.micrometerspingboot").tags(new String[]{"name","counterTwo"}).description("This is the two counter").register(meterRegistry);
        this.counterThree = Counter.builder("com.citydo.micrometerspingboot").tags(new String[]{"name","counterThree"}).description("This is the three counter").register(meterRegistry);

        Gauge.builder("com.citydo.micrometerspingboot",map, x-> x.get("x")).tags("name","gauge").description("This is the gauge").register(meterRegistry);
    }
}